package service.impl;

import dao.DeptDao;
import dao.impl.DeptDaoImpl;
import org.apache.ibatis.session.SqlSession;
import pojo.Dept;
import service.DeptService;
import util.MyBatisUtil;

import java.util.List;

public class DeptServiceImpl implements DeptService {

    DeptDao deptDao = new DeptDaoImpl();

    @Override
    public List<Dept> findAll() {
        return deptDao.findAll();
    }

    @Override
    public int addDept(Dept dept) {
        return deptDao.addDept(dept);
    }
    @Override
    public int deleteDept(int id) {
        return deptDao.deleteDept(id);
    }
    @Override
    public Dept findDeptById(int id) {
        return deptDao.findDeptById(id);
    }

    @Override
    public int updateDept(Dept dept) {
        SqlSession session = MyBatisUtil.getSession();
        int result = session.getMapper(DeptDao.class).updateDept(dept);
        session.commit();
        return result;
    }
}
